using System;
using System.Data;

// use OLE DB .NET Data Provider namespace
using System.Data.OleDb;

namespace ekhang.BeginningCSharpDatabases.Chapter03 
{
  class ConnectionExample3
  {
    static void Main() 
    {
      // create OleDbConnection object
      OleDbConnection thisConnection = new OleDbConnection(
        @"Provider=Microsoft.Jet.OLEDB.4.0;" +   
        @"Data Source=" +        // Data Source = path name of .mdb file 
        @"C:\Program Files\Microsoft Office\Office\Samples" +
        @"\Northwind.mdb");

      try 
      {
        // open connection
        thisConnection.Open();
        // open was successful    
        Console.WriteLine("OLE DB Connection Successfully Opened!");
        Console.WriteLine("Connection Properties:");  
        Console.WriteLine("\tConnection String: {0}", 
          thisConnection.ConnectionString); 
        Console.WriteLine("\tDatabase: {0}", thisConnection.Database);   
        Console.WriteLine("\tDataSource: {0}", thisConnection.DataSource);
        Console.WriteLine("\tServerVersion: {0}", 
          thisConnection.ServerVersion);
        Console.WriteLine("\tState: {0}", thisConnection.State);
        // OLE DB-specific properties
        Console.WriteLine("\tProvider: {0}", thisConnection.Provider);
      } 
      catch (OleDbException ex) 
      {
        Console.WriteLine(ex.ToString());
      }
      finally 
      {
        // close connection
        thisConnection.Close();
        // close was closed by finally block  
        Console.WriteLine("Connection Closed.");
      }
    }  
  }
}
